/**
 * Created by admin on 2017/4/20.
 */
$(function () {
    $.ajax({
        url:'/imgcode',
        datatype: 'json',
        type: 'get',
        data:{},
        success: function (data) {
            $('#sp_1').html(data);
        },
        error: function(xhr) {
            alert('error:' + JSON.stringify(xhr));
        }
    })
})

function changeImg() {
    alert("1")
    var imgSrc = $("#imgObj");
    var src = imgSrc.attr("src");
    imgSrc.attr("src", chgUrl(src));
}
//时间戳
//为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳
function chgUrl(url) {
    var timestamp = (new Date()).valueOf();
    url = url.substring(0, 17);
    if ((url.indexOf("&") >= 0)) {
        url = url + "×tamp=" + timestamp;
    } else {
        url = url + "?timestamp=" + timestamp;
    }
    return url;
}